#! /bin/sh

VERSION=`gawk -f ../../../give2-give2/scripts/get-version.awk give2-example-nlgserver/pom.xml`
BASENAME=give2-demo-nlgservers-$VERSION
BASE=/tmp/$BASENAME

rm -rf $BASE /tmp/$BASENAME.zip /tmp/$BASENAME.tar.gz
mkdir $BASE

# copy directory trees over
cp -r give2-example-nlgserver $BASE
cp -r give2-dummy-nlgserver $BASE
rm $BASE/*/scripts/dist*

# set versions in start-server scripts
sed s/VERSION/$VERSION/ give2-example-nlgserver/scripts/dist-start-example-nlgserver > $BASE/give2-example-nlgserver/scripts/start-example-nlgserver
sed s/VERSION/$VERSION/ give2-dummy-nlgserver/scripts/dist-start-dummy-nlgserver > $BASE/give2-dummy-nlgserver/scripts/start-dummy-nlgserver
chmod 755 $BASE/give2-example-nlgserver/scripts/start-example-nlgserver
chmod 755 $BASE/give2-dummy-nlgserver/scripts/start-dummy-nlgserver

# clean up .svn subdirectories
cd $BASE
find . -name '.svn'|xargs rm -rf
find . -name 'target'|xargs rm -rf

# build archives
cd ..
tar czvf $BASENAME.tar.gz $BASENAME
zip -r $BASENAME.zip $BASENAME

